﻿using System;
using System.Collections.Generic;
using System.Linq;
using RimWorld;
using UnityEngine;
using Verse;
using Verse.Sound;

//一模一样的代码错误：
//Exception ticking D-EC-1E (at (62, 0, 72)): System.NullReferenceException: Object reference not set to an instance of an object
//[Ref B482AB18] Duplicate stacktrace, see ref for original

namespace Miao.ArchotechFix
{
    public class Verb_ShootBeamLaser : Verb
    {
        //private List<Vector3> path = new List<Vector3>();

        //private List<Vector3> tmpPath = new List<Vector3>();

        private int ticksToNextPathStep;

        private Vector3 initialTargetPosition;

        private MoteDualAttached mote;

        private Effecter endEffecter;

        private Sustainer sustainer;

        //private HashSet<IntVec3> pathCells = new HashSet<IntVec3>();

        private HashSet<IntVec3> tmpPathCells = new HashSet<IntVec3>();

        //private HashSet<IntVec3> hitCells = new HashSet<IntVec3>();

        private const int NumSubdivisionsPerUnitLength = 1;

        protected override int ShotsPerBurst => verbProps.burstShotCount;

        public float ShotProgress => (float)ticksToNextPathStep / (float)verbProps.ticksBetweenBurstShots;
        /// <summary>
        /// 互通位置?
        /// </summary>
        public Vector3 InterpolatedPosition
        {
            get
            {
                //Vector3 vector = base.CurrentTarget.CenterVector3 - initialTargetPosition;
                return initialTargetPosition;
                //return Vector3.Lerp(path[burstShotsLeft], path[Mathf.Min(burstShotsLeft + 1, path.Count - 1)], ShotProgress) + vector;
            }
        }

        public override float? AimAngleOverride
        {
            get
            {
                if (state != VerbState.Bursting)
                {
                    return null;
                }
                return (InterpolatedPosition - caster.DrawPos).AngleFlat();
            }
        }

        public override void DrawHighlight(LocalTargetInfo target)
        {
            base.DrawHighlight(target);
            //CalculatePath(target.CenterVector3, tmpPath, tmpPathCells, addRandomOffset: false);
            GenDraw.DrawFieldEdges(tmpPathCells.ToList());
        }

        protected override bool TryCastShot()
        {
            if (currentTarget.HasThing && currentTarget.Thing.Map != caster.Map)
            {
                return false;
            }
            ShootLine resultingLine;
            bool flag = TryFindShootLineFromTo(caster.Position, currentTarget, out resultingLine);
            if (verbProps.stopBurstWithoutLos && !flag)
            {
                return false;
            }
            if (base.EquipmentSource != null)
            {
                base.EquipmentSource.GetComp<CompChangeableProjectile>()?.Notify_ProjectileLaunched();
                base.EquipmentSource.GetComp<CompApparelReloadable>()?.UsedOnce();
            }
            lastShotTick = Find.TickManager.TicksGame;
            ticksToNextPathStep = verbProps.ticksBetweenBurstShots;
            IntVec3 interpolatedPosition = InterpolatedPosition.Yto0().ToIntVec3();
            //IntVec3 intVec2 = GenSight.LastPointOnLineOfSight(resultingLine.Source, interpolatedPosition, (IntVec3 c) => c.InBounds(caster.Map) && c.CanBeSeenOverFast(caster.Map), skipFirstCell: true);
            //IntVec3 intVec3 = ((!verbProps.beamCantHitWithinMinRange || !(intVec2.DistanceTo(resultingLine.Source) < verbProps.minRange)) ? (intVec2.IsValid ? intVec2 : interpolatedPosition) : interpolatedPosition);
            //HitCell(intVec3, resultingLine.Source);

            HitCell(interpolatedPosition, resultingLine.Source);
            //if (verbProps.beamHitsNeighborCells)
            //{
            //    hitCells.Add(intVec3);
            //    for (int i = 0; i < 4; i++)
            //    {
            //        IntVec3 intVec4 = intVec3 + GenAdj.CardinalDirections[i];
            //        if (intVec4.InBounds(Caster.Map) && !hitCells.Contains(intVec4) && (!verbProps.beamHitsNeighborCellsRequiresLOS || GenSight.LineOfSight(resultingLine.Source, intVec4, caster.Map)))
            //        {
            //            float damageFactor = (pathCells.Contains(intVec4) ? 1f : 0.5f);
            //            HitCell(intVec4, resultingLine.Source, damageFactor);
            //            hitCells.Add(intVec4);
            //        }
            //    }
            //}
            return true;
        }

        public override bool TryStartCastOn(LocalTargetInfo castTarg, LocalTargetInfo destTarg, bool surpriseAttack = false, bool canHitNonTargetPawns = true, bool preventFriendlyFire = false, bool nonInterruptingSelfCast = false)
        {
            return base.TryStartCastOn(verbProps.beamTargetsGround ? ((LocalTargetInfo)castTarg.Cell) : castTarg, destTarg, surpriseAttack, canHitNonTargetPawns, preventFriendlyFire, nonInterruptingSelfCast);
        }

        public override void BurstingTick()
        {
            ticksToNextPathStep--;
            Vector3 vector = InterpolatedPosition;
            IntVec3 intVec = vector.ToIntVec3();
            Vector3 vector2 = InterpolatedPosition - caster.Position.ToVector3Shifted();
            float num = vector2.MagnitudeHorizontal();
            Vector3 normalized = vector2.Yto0().normalized;
            IntVec3 intVec2 = GenSight.LastPointOnLineOfSight(caster.Position, intVec, (IntVec3 c) => c.CanBeSeenOverFast(caster.Map), skipFirstCell: true);
            if (intVec2.IsValid)
            {
                num -= (intVec - intVec2).LengthHorizontal;
                vector = caster.Position.ToVector3Shifted() + normalized * num;
                intVec = vector.ToIntVec3();
            }
            Vector3 offsetA = normalized * verbProps.beamStartOffset;
            Vector3 vector3 = vector - intVec.ToVector3Shifted();
            if (mote != null)
            {
                mote.UpdateTargets(new TargetInfo(caster.Position, caster.Map), new TargetInfo(intVec, caster.Map), offsetA, vector3);
                mote.Maintain();
            }
            if (verbProps.beamGroundFleckDef != null && Rand.Chance(verbProps.beamFleckChancePerTick))
            {
                FleckMaker.Static(vector, caster.Map, verbProps.beamGroundFleckDef);
            }
            if (endEffecter == null && verbProps.beamEndEffecterDef != null)
            {
                endEffecter = verbProps.beamEndEffecterDef.Spawn(intVec, caster.Map, vector3);
            }
            if (endEffecter != null)
            {
                endEffecter.offset = vector3;
                endEffecter.EffectTick(new TargetInfo(intVec, caster.Map), TargetInfo.Invalid);
                endEffecter.ticksLeft--;
            }
            if (verbProps.beamLineFleckDef != null)
            {
                float num2 = 1f * num;
                for (int i = 0; (float)i < num2; i++)
                {
                    if (Rand.Chance(verbProps.beamLineFleckChanceCurve.Evaluate((float)i / num2)))
                    {
                        Vector3 vector4 = i * normalized - normalized * Rand.Value + normalized / 2f;
                        FleckMaker.Static(caster.Position.ToVector3Shifted() + vector4, caster.Map, verbProps.beamLineFleckDef);
                    }
                }
            }
            sustainer?.Maintain();
        }
        /// <summary>
        /// 冷却完成
        /// </summary>
        public override void WarmupComplete()
        {
            burstShotsLeft = ShotsPerBurst;
            state = VerbState.Bursting;
            initialTargetPosition = currentTarget.CenterVector3;
            //CalculatePath(currentTarget.CenterVector3, path, pathCells);
            //hitCells.Clear();
            if (verbProps.beamMoteDef != null)
            {
                mote = MoteMaker.MakeInteractionOverlay(verbProps.beamMoteDef, caster, new TargetInfo(initialTargetPosition.ToIntVec3(), caster.Map));
                //mote = MoteMaker.MakeInteractionOverlay(verbProps.beamMoteDef, caster, new TargetInfo(path[0].ToIntVec3(), caster.Map));
            }
            TryCastNextBurstShot();
            ticksToNextPathStep = verbProps.ticksBetweenBurstShots;
            endEffecter?.Cleanup();
            if (verbProps.soundCastBeam != null)
            {
                sustainer = verbProps.soundCastBeam.TrySpawnSustainer(SoundInfo.InMap(caster, MaintenanceType.PerTick));
            }
        }

        private void CalculatePath(Vector3 target, List<Vector3> pathList, HashSet<IntVec3> pathCellsList, bool addRandomOffset = true)
        {
            pathList.Clear();
            Vector3 vector = (target - caster.Position.ToVector3Shifted()).Yto0();
            float magnitude = vector.magnitude;
            Vector3 normalized = vector.normalized;
            Vector3 vector2 = normalized.RotatedBy(-90f);
            float num = ((verbProps.beamFullWidthRange > 0f) ? Mathf.Min(magnitude / verbProps.beamFullWidthRange, 1f) : 1f);
            float num2 = (verbProps.beamWidth + 1f) * num / (float)ShotsPerBurst;
            Vector3 vector3 = target.Yto0() - vector2 * verbProps.beamWidth / 2f * num;
            pathList.Add(vector3);
            for (int i = 0; i < ShotsPerBurst; i++)
            {
                Vector3 vector4 = normalized * (Rand.Value * verbProps.beamMaxDeviation) - normalized / 2f;
                Vector3 vector5 = Mathf.Sin(((float)i / (float)ShotsPerBurst + 0.5f) * (float)Math.PI * 57.29578f) * verbProps.beamCurvature * -normalized - normalized * verbProps.beamMaxDeviation / 2f;
                if (addRandomOffset)
                {
                    pathList.Add(vector3 + (vector4 + vector5) * num);
                }
                else
                {
                    pathList.Add(vector3 + vector5 * num);
                }
                vector3 += vector2 * num2;
            }
            pathCellsList.Clear();
            foreach (Vector3 path in pathList)
            {
                pathCellsList.Add(path.ToIntVec3());
            }
        }

        private bool CanHit(Thing thing)
        {
            if (!thing.Spawned)
            {
                return false;
            }
            return !CoverUtility.ThingCovered(thing, caster.Map);
        }

        private void HitCell(IntVec3 cell, IntVec3 sourceCell, float damageFactor = 1f)
        {
            if (cell.InBounds(caster.Map))
            {
                ApplyDamage(VerbUtility.ThingsToHit(cell, caster.Map, CanHit).RandomElementWithFallback(), sourceCell, damageFactor);
                if (verbProps.beamSetsGroundOnFire && Rand.Chance(verbProps.beamChanceToStartFire))
                {
                    FireUtility.TryStartFireIn(cell, caster.Map, 1f, caster);
                }
            }
        }

        private void ApplyDamage(Thing thing, IntVec3 sourceCell, float damageFactor = 1f)
        {
            IntVec3 intVec = InterpolatedPosition.Yto0().ToIntVec3();
            IntVec3 intVec2 = GenSight.LastPointOnLineOfSight(sourceCell, intVec, (IntVec3 c) => c.InBounds(caster.Map) && c.CanBeSeenOverFast(caster.Map), skipFirstCell: true);
            if (intVec2.IsValid)
            {
                intVec = intVec2;
            }
            Map map = caster.Map;
            if (thing == null || verbProps.beamDamageDef == null)//这里的错误应该和DamageDef没有关系 Beam
            {
                return;
            }
            float angleFlat = (currentTarget.Cell - caster.Position).AngleFlat;
            //BattleLogEntry_RangedImpact log = new BattleLogEntry_RangedImpact(caster, thing, currentTarget.Thing, base.EquipmentSource.def, null, null);
            DamageInfo dinfo;
            //if (verbProps.beamTotalDamage > 0f)
            //{
            //    float num = verbProps.beamTotalDamage / (float)pathCells.Count;
            //    num *= damageFactor;
            //    dinfo = new DamageInfo(verbProps.beamDamageDef, num, verbProps.beamDamageDef.defaultArmorPenetration, angleFlat, caster, null,null, DamageInfo.SourceCategory.ThingOrUnknown, currentTarget.Thing);
            //}
            //else
            //{
            //    float amount = (float)verbProps.beamDamageDef.defaultDamage * damageFactor;
            //    dinfo = new DamageInfo(verbProps.beamDamageDef, amount, verbProps.beamDamageDef.defaultArmorPenetration, angleFlat, caster, null, null, DamageInfo.SourceCategory.ThingOrUnknown, currentTarget.Thing);
            //}

            float amount = (float)verbProps.beamDamageDef.defaultDamage * damageFactor;
            dinfo = new DamageInfo(verbProps.beamDamageDef, amount, verbProps.beamDamageDef.defaultArmorPenetration, angleFlat, caster, null, null, DamageInfo.SourceCategory.ThingOrUnknown, currentTarget.Thing);

            //thing.TakeDamage(dinfo).AssociateWithLog(log);
            thing.TakeDamage(dinfo);
            if (thing.CanEverAttachFire())
            {
                float chance = ((verbProps.flammabilityAttachFireChanceCurve == null) ? verbProps.beamChanceToAttachFire : verbProps.flammabilityAttachFireChanceCurve.Evaluate(thing.GetStatValue(StatDefOf.Flammability)));
                if (Rand.Chance(chance))
                {
                    thing.TryAttachFire(verbProps.beamFireSizeRange.RandomInRange, caster);
                }
            }
            else if (Rand.Chance(verbProps.beamChanceToStartFire))
            {
                FireUtility.TryStartFireIn(intVec, map, verbProps.beamFireSizeRange.RandomInRange, caster, verbProps.flammabilityAttachFireChanceCurve);
            }
        }

        public override void ExposeData()
        {
            base.ExposeData();
            //Scribe_Collections.Look(ref path, "path", LookMode.Value);
            Scribe_Values.Look(ref ticksToNextPathStep, "ticksToNextPathStep", 0);
            Scribe_Values.Look(ref initialTargetPosition, "initialTargetPosition");
            //if (Scribe.mode == LoadSaveMode.PostLoadInit && path == null)
            //{
            //    path = new List<Vector3>();
            //}
        }
    }
}

//namespace Miao.ArchotechFix
//{
//    using System;
//    using System.Collections.Generic;
//    using System.Linq;
//    using RimWorld;
//    using UnityEngine;
//    using Verse.Sound;
//    public class Verb_ShootBeamLaser : Verb
//    {
//        //private List<Vector3> path = new List<Vector3>();

//        private List<Vector3> tmpPath = new List<Vector3>();

//        private int ticksToNextPathStep;

//        private Vector3 initialTargetPosition;

//        private MoteDualAttached mote;

//        private Effecter endEffecter;

//        private Sustainer sustainer;

//        //private HashSet<IntVec3> pathCells = new HashSet<IntVec3>();

//        //private HashSet<IntVec3> tmpPathCells = new HashSet<IntVec3>();

//        private HashSet<IntVec3> hitCells = new HashSet<IntVec3>();

//        private const int NumSubdivisionsPerUnitLength = 1;

//        protected override int ShotsPerBurst => verbProps.burstShotCount;

//        public float ShotProgress => (float)ticksToNextPathStep / (float)verbProps.ticksBetweenBurstShots;

//        public Vector3 InterpolatedPosition
//        {
//            get
//            {
//                Vector3 vector = base.CurrentTarget.CenterVector3 - initialTargetPosition;
//                return Vector3.Lerp(path[burstShotsLeft], path[Mathf.Min(burstShotsLeft + 1, path.Count - 1)], ShotProgress) + vector;
//            }
//        }

//        public override float? AimAngleOverride
//        {
//            get
//            {
//                if (state != VerbState.Bursting)
//                {
//                    return null;
//                }
//                return (InterpolatedPosition - caster.DrawPos).AngleFlat();
//            }
//        }

//        public override void DrawHighlight(LocalTargetInfo target)
//        {
//            base.DrawHighlight(target);
//            //CalculatePath(target.CenterVector3, tmpPath, tmpPathCells, addRandomOffset: false);
//            //GenDraw.DrawFieldEdges(tmpPathCells.ToList());
//        }

//        protected override bool TryCastShot()
//        {
//            if (currentTarget.HasThing && currentTarget.Thing.Map != caster.Map)
//            {
//                return false;
//            }
//            ShootLine resultingLine;
//            bool flag = TryFindShootLineFromTo(caster.Position, currentTarget, out resultingLine);
//            if (verbProps.stopBurstWithoutLos && !flag)
//            {
//                return false;
//            }
//            if (base.EquipmentSource != null)
//            {
//                base.EquipmentSource.GetComp<CompChangeableProjectile>()?.Notify_ProjectileLaunched();
//                base.EquipmentSource.GetComp<CompApparelReloadable>()?.UsedOnce();
//            }
//            lastShotTick = Find.TickManager.TicksGame;
//            ticksToNextPathStep = verbProps.ticksBetweenBurstShots;
//            IntVec3 intVec = InterpolatedPosition.Yto0().ToIntVec3();
//            IntVec3 intVec2 = GenSight.LastPointOnLineOfSight(resultingLine.Source, intVec, (IntVec3 c) => c.InBounds(caster.Map) && c.CanBeSeenOverFast(caster.Map), skipFirstCell: true);
//            IntVec3 intVec3 = ((!verbProps.beamCantHitWithinMinRange || !(intVec2.DistanceTo(resultingLine.Source) < verbProps.minRange)) ? (intVec2.IsValid ? intVec2 : intVec) : intVec);
//            HitCell(intVec3, resultingLine.Source);

//            //if (verbProps.beamHitsNeighborCells)//临近伤害造成
//            //{
//            //    hitCells.Add(intVec3);
//            //    for (int i = 0; i < 4; i++)
//            //    {
//            //        IntVec3 intVec4 = intVec3 + GenAdj.CardinalDirections[i];
//            //        if (intVec4.InBounds(Caster.Map) && !hitCells.Contains(intVec4) && (!verbProps.beamHitsNeighborCellsRequiresLOS || GenSight.LineOfSight(resultingLine.Source, intVec4, caster.Map)))
//            //        {
//            //            float damageFactor = (pathCells.Contains(intVec4) ? 1f : 0.5f);

//            //            HitCell(intVec4, resultingLine.Source, damageFactor);
//            //            hitCells.Add(intVec4);
//            //        }
//            //    }
//            //}
//            return true;
//        }

//        public override bool TryStartCastOn(LocalTargetInfo castTarg, LocalTargetInfo destTarg, bool surpriseAttack = false, bool canHitNonTargetPawns = true, bool preventFriendlyFire = false, bool nonInterruptingSelfCast = false)
//        {
//            return base.TryStartCastOn(verbProps.beamTargetsGround ? ((LocalTargetInfo)castTarg.Cell) : castTarg, destTarg, surpriseAttack, canHitNonTargetPawns, preventFriendlyFire, nonInterruptingSelfCast);
//        }

//        public override void BurstingTick()
//        {
//            ticksToNextPathStep--;
//            Vector3 vector = InterpolatedPosition;
//            IntVec3 intVec = vector.ToIntVec3();
//            Vector3 vector2 = InterpolatedPosition - caster.Position.ToVector3Shifted();
//            float num = vector2.MagnitudeHorizontal();
//            Vector3 normalized = vector2.Yto0().normalized;
//            IntVec3 intVec2 = GenSight.LastPointOnLineOfSight(caster.Position, intVec, (IntVec3 c) => c.CanBeSeenOverFast(caster.Map), skipFirstCell: true);
//            if (intVec2.IsValid)
//            {
//                num -= (intVec - intVec2).LengthHorizontal;
//                vector = caster.Position.ToVector3Shifted() + normalized * num;
//                intVec = vector.ToIntVec3();
//            }
//            Vector3 offsetA = normalized * verbProps.beamStartOffset;
//            Vector3 vector3 = vector - intVec.ToVector3Shifted();
//            if (mote != null)
//            {
//                mote.UpdateTargets(new TargetInfo(caster.Position, caster.Map), new TargetInfo(intVec, caster.Map), offsetA, vector3);
//                mote.Maintain();
//            }
//            if (verbProps.beamGroundFleckDef != null && Rand.Chance(verbProps.beamFleckChancePerTick))
//            {
//                FleckMaker.Static(vector, caster.Map, verbProps.beamGroundFleckDef);
//            }
//            if (endEffecter == null && verbProps.beamEndEffecterDef != null)
//            {
//                endEffecter = verbProps.beamEndEffecterDef.Spawn(intVec, caster.Map, vector3);
//            }
//            if (endEffecter != null)
//            {
//                endEffecter.offset = vector3;
//                endEffecter.EffectTick(new TargetInfo(intVec, caster.Map), TargetInfo.Invalid);
//                endEffecter.ticksLeft--;
//            }
//            if (verbProps.beamLineFleckDef != null)
//            {
//                float num2 = 1f * num;
//                for (int i = 0; (float)i < num2; i++)
//                {
//                    if (Rand.Chance(verbProps.beamLineFleckChanceCurve.Evaluate((float)i / num2)))
//                    {
//                        Vector3 vector4 = i * normalized - normalized * Rand.Value + normalized / 2f;
//                        FleckMaker.Static(caster.Position.ToVector3Shifted() + vector4, caster.Map, verbProps.beamLineFleckDef);
//                    }
//                }
//            }
//            sustainer?.Maintain();
//        }

//        public override void WarmupComplete()
//        {
//            burstShotsLeft = ShotsPerBurst;
//            state = VerbState.Bursting;
//            initialTargetPosition = currentTarget.CenterVector3;
//            //pathCells<-这个不需要
//            //CalculatePath(currentTarget.CenterVector3, path, pathCells);
//            hitCells.Clear();
//            if (verbProps.beamMoteDef != null)
//            {
//                mote = MoteMaker.MakeInteractionOverlay(verbProps.beamMoteDef, caster, new TargetInfo(path[0].ToIntVec3(), caster.Map));
//            }
//            TryCastNextBurstShot();
//            ticksToNextPathStep = verbProps.ticksBetweenBurstShots;
//            endEffecter?.Cleanup();
//            if (verbProps.soundCastBeam != null)
//            {
//                sustainer = verbProps.soundCastBeam.TrySpawnSustainer(SoundInfo.InMap(caster, MaintenanceType.PerTick));
//            }
//        }

//        private void CalculatePath(Vector3 target, List<Vector3> pathList, HashSet<IntVec3> pathCellsList, bool addRandomOffset = true)
//        {
//            pathList.Clear();
//            Vector3 vector = (target - caster.Position.ToVector3Shifted()).Yto0();
//            float magnitude = vector.magnitude;
//            Vector3 normalized = vector.normalized;
//            Vector3 vector2 = normalized.RotatedBy(-90f);
//            float num = ((verbProps.beamFullWidthRange > 0f) ? Mathf.Min(magnitude / verbProps.beamFullWidthRange, 1f) : 1f);
//            float num2 = (verbProps.beamWidth + 1f) * num / (float)ShotsPerBurst;
//            Vector3 vector3 = target.Yto0() - vector2 * verbProps.beamWidth / 2f * num;
//            pathList.Add(vector3);
//            for (int i = 0; i < ShotsPerBurst; i++)
//            {
//                Vector3 vector4 = normalized * (Rand.Value * verbProps.beamMaxDeviation) - normalized / 2f;
//                Vector3 vector5 = Mathf.Sin(((float)i / (float)ShotsPerBurst + 0.5f) * (float)Math.PI * 57.29578f) * verbProps.beamCurvature * -normalized - normalized * verbProps.beamMaxDeviation / 2f;
//                if (addRandomOffset)
//                {
//                    pathList.Add(vector3 + (vector4 + vector5) * num);
//                }
//                else
//                {
//                    pathList.Add(vector3 + vector5 * num);
//                }
//                vector3 += vector2 * num2;
//            }
//            //pathCellsList.Clear();
//            //foreach (Vector3 path in pathList)
//            //{
//            //    pathCellsList.Add(path.ToIntVec3());
//            //}
//        }

//        private bool CanHit(Thing thing)
//        {
//            if (!thing.Spawned)
//            {
//                return false;
//            }
//            return !CoverUtility.ThingCovered(thing, caster.Map);
//        }

//        private void HitCell(IntVec3 cell, IntVec3 sourceCell, float damageFactor = 1f)
//        {
//            if (cell.InBounds(caster.Map))
//            {
//                ApplyDamage(VerbUtility.ThingsToHit(cell, caster.Map, CanHit).RandomElementWithFallback(), sourceCell, damageFactor);
//                if (verbProps.beamSetsGroundOnFire && Rand.Chance(verbProps.beamChanceToStartFire))
//                {
//                    FireUtility.TryStartFireIn(cell, caster.Map, 1f, caster);
//                }
//            }
//        }

//        private void ApplyDamage(Thing thing, IntVec3 sourceCell, float damageFactor = 1f)
//        {
//            IntVec3 intVec = InterpolatedPosition.Yto0().ToIntVec3();
//            IntVec3 intVec2 = GenSight.LastPointOnLineOfSight(sourceCell, intVec, (IntVec3 c) => c.InBounds(caster.Map) && c.CanBeSeenOverFast(caster.Map), skipFirstCell: true);
//            if (intVec2.IsValid)
//            {
//                intVec = intVec2;
//            }
//            Map map = caster.Map;
//            if (thing == null || verbProps.beamDamageDef == null)
//            {
//                return;
//            }
//            float angleFlat = (currentTarget.Cell - caster.Position).AngleFlat;
//            BattleLogEntry_RangedImpact log = new BattleLogEntry_RangedImpact(caster, thing, currentTarget.Thing, base.EquipmentSource.def, null, null);
//            DamageInfo dinfo;
//            if (verbProps.beamTotalDamage > 0f)
//            {
//                float num = verbProps.beamTotalDamage;
//                //float num = verbProps.beamTotalDamage / (float)pathCells.Count;
//                num *= damageFactor;
//                dinfo = new DamageInfo(verbProps.beamDamageDef, num, verbProps.beamDamageDef.defaultArmorPenetration, angleFlat, caster, null, base.EquipmentSource.def, DamageInfo.SourceCategory.ThingOrUnknown, currentTarget.Thing);
//            }
//            else
//            {
//                float amount = (float)verbProps.beamDamageDef.defaultDamage * damageFactor;
//                dinfo = new DamageInfo(verbProps.beamDamageDef, amount, verbProps.beamDamageDef.defaultArmorPenetration, angleFlat, caster, null, base.EquipmentSource.def, DamageInfo.SourceCategory.ThingOrUnknown, currentTarget.Thing);
//            }
//            thing.TakeDamage(dinfo).AssociateWithLog(log);
//            if (thing.CanEverAttachFire())
//            {
//                float chance = ((verbProps.flammabilityAttachFireChanceCurve == null) ? verbProps.beamChanceToAttachFire : verbProps.flammabilityAttachFireChanceCurve.Evaluate(thing.GetStatValue(StatDefOf.Flammability)));
//                if (Rand.Chance(chance))
//                {
//                    thing.TryAttachFire(verbProps.beamFireSizeRange.RandomInRange, caster);
//                }
//            }
//            else if (Rand.Chance(verbProps.beamChanceToStartFire))
//            {
//                FireUtility.TryStartFireIn(intVec, map, verbProps.beamFireSizeRange.RandomInRange, caster, verbProps.flammabilityAttachFireChanceCurve);
//            }
//        }

//        public override void ExposeData()
//        {
//            base.ExposeData();
//            Scribe_Collections.Look(ref path, "path", LookMode.Value);
//            Scribe_Values.Look(ref ticksToNextPathStep, "ticksToNextPathStep", 0);
//            Scribe_Values.Look(ref initialTargetPosition, "initialTargetPosition");
//            if (Scribe.mode == LoadSaveMode.PostLoadInit && path == null)
//            {
//                path = new List<Vector3>();
//            }
//        }
//    }
//}

